package com.zj.jdbc2ThreadLocal;

import com.zj.bean.UserInfo;
import com.zj.jdbc2ThreadLocal.tools.JdbcThreadLocal;

import java.util.ArrayList;
import java.util.List;

public class JdbcService {


    public List<UserInfo> doBusiness(UserInfo user,int id) {
        List<UserInfo> all=new ArrayList<>();
        try{
            JdbcThreadLocal.startTransaction();
            UserDaoImpl userDao=SingletonEnum.INSTANCE.getUserDao();
            userDao.update(user,id);
            all = userDao.getAll();
//            int a=1/0;
            JdbcThreadLocal.commit();
        }catch (Exception e){
            e.printStackTrace();
            JdbcThreadLocal.rollback();
        }finally {
            JdbcThreadLocal.close();
            return all;
        }


    }
}
